<?php
/* @var $this BlocksController */
/* @var $model Blocks */
/* @var $form CActiveForm */
?>

<div class="form">
<?php 
$fieldsStr = isset($model->type) ? $model->type->fields : 'id,show_header,name,anons,text,type_id,video_url,crdate,file,url';
$fields = explode(',',$fieldsStr);
?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'blocks-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
	<div class="tabs">
		<a href="#tab_<?php echo Yii::app()->params->language; ?>" class="tab active"><?php echo Yii::app()->params->language; ?></a>
		<?php foreach(Yii::app()->params->languages as $key => $value): ?>
			<a href="#tab_<?php echo $key; ?>" class="tab"><?php echo $key; ?></a>
		<?php endforeach;?>
	</div>
	
	<div id="tab_<?php echo Yii::app()->params->language; ?>" class="screen visible">
		<?php if(in_array('name', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'name'); ?>
				<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>1000)); ?>
				<?php echo $form->error($model,'name'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('show_header', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'show_header'); ?>
				<?php 
					echo $form->dropDownList($model, 'show_header',
					array(
						'0' => 'Нет',
						'1' => 'Да', 
					)); 
				?>
				<?php echo $form->error($model,'show_header'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('anons', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'anons'); ?>
				<?php echo $form->textArea($model,'anons'); ?>
				<?php echo $form->error($model,'anons'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('text', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'text'); ?>
				<?php EWysiwyg::show($this, $model, 'text', isset($model->text) ? $model->text : ''); ?>
				<?php echo $form->error($model,'text'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('type_id', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'type_id'); ?>
				<?php echo $form->dropDownList($model,'type_id',CSelect::items('BlocksType'),  array('empty' => ('Выберите тип'))); ?>
				<?php echo $form->error($model,'type_id'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('video_url', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'video_url'); ?>
				<?php echo $form->textField($model,'video_url',array('size'=>60,'maxlength'=>255)); ?>
				<?php echo $form->error($model,'video_url'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('crdate', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'crdate'); ?>
				<?php echo $form->textField($model,'crdate'); ?>
				<?php echo $form->error($model,'crdate'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('file', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'file'); ?>
				<?php $this->widget('ext.elfinder.ServerFileInput', array(
				        'model' => $model,
				        'attribute' => 'file',
				        'connectorRoute'=>CHtml::normalizeUrl(array('site/fileManager')),
			        )
				); ?>
				<?php echo $form->error($model,'file'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('url', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'url'); ?>
				<?php echo $form->textField($model,'url',array('size'=>60,'maxlength'=>255)); ?>
				<?php echo $form->error($model,'url'); ?>
			</div>
		<?php endif; ?>
	</div>
	<?php 
	$lns = Yii::app()->params->languages; 
	$names = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'name') : array();
	$anons = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'anons') : array();
	$text = isset($model->lns) ? CHtml::listData($model->lns, 'ln', 'text') : array();
	foreach($lns as $key => $value) : 
	?>
	<div id="tab_<?php echo $key; ?>" class="screen">
		<?php if(in_array('name', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'name'); ?>
				<?php echo $form->textField($model,'[lns]['.$key.']name',array('size'=>60,'maxlength'=>255, 'value'=> isset($names[$key]) ? $names[$key] : '' )); ?>
				<?php echo $form->error($model,'name'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('anons', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'anons'); ?>
				<?php echo $form->textArea($model,'[lns]['.$key.']anons', array('value'=> isset($anons[$key]) ? $anons[$key] : '' )); ?>
				<?php echo $form->error($model,'anons'); ?>
			</div>
		<?php endif; ?>
		<?php if(in_array('text', $fields) ) :?>
			<div class="row">
				<?php echo $form->labelEx($model,'text'); ?>
				<?php EWysiwyg::show($this, $model, '[lns]['.$key.']text', isset($text[$key]) ? $text[$key] : '');?>
				<?php echo $form->error($model,'text'); ?>
			</div>
		<?php endif; ?>
	</div>
	<?php endforeach;?>
<?php $this->endWidget(); ?>

</div><!-- form -->